module.exports = {
	before: async (state, event) => {
		let db = uniCloud.database()
		let amount = state.newData.amount
		let transaction = await db.startTransaction()
		let qrcodeIds = []
		for (var i = 0; i < amount; i++) {
			let res = await db.collection('t3ds-qrcode').add({
				bizCode: '01',
				validTime: state.newData.deadline
			})
			qrcodeIds.push(res.id)
		}
		state.newData.qrcodeIds = qrcodeIds
		state.transaction = transaction
	},
	after: async (state, event, error, result) => {
		if (error) {
			await state.transaction.rollback()
			throw error
		}
		await state.transaction.commit()
		return result
	}
}